
// 获取首屏时间（简易版）
const targetNode = document.body;
let timeObject = { nodeLength: 0, time: window.performance.now() };

const observer = new MutationObserver(mutationsList =>
  timeObject = mutationsList.length > timeObject.nodeLength ?
    { nodeLength: mutationsList.length, time: window.performance.now() } :
    timeObject
);

observer.observe(targetNode, { childList: true, subtree: true });

// 2s内获取最大值
setTimeout(() => {

  const {
    domainLookupStart,
    domainLookupEnd,
    responseEnd,
    domComplete,
    domLoading,
    requestStart
  } = window.performance.timing;

  window.performanceObj = {
    ...window.performanceObj,
    firstScreenTime: timeObject.time,
    DNSTime: domainLookupEnd - domainLookupStart,
    requestTime: responseEnd - requestStart,
    domTime: domComplete - domLoading
  }

  console.log('performace-time>>>', window.performanceObj)

  observer.disconnect();
}, 2000)